package com.changgou.oauth.config;

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ljh
 * @version 1.0
 * @date 2021/1/6 18:17
 * @description 标题
 * @package com.changgou.oauth.config
 */

public class MyTokenEnhancer extends JwtAccessTokenConverter implements TokenEnhancer {
    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        OAuth2AccessToken result = super.enhance(accessToken, authentication);
        DefaultOAuth2AccessToken defaultOAuth2AccessToken = (DefaultOAuth2AccessToken)result;
        Map<String,Object> addition = new HashMap<String,Object>();
        addition.put("abc","def");
        defaultOAuth2AccessToken.setAdditionalInformation(addition);
        return defaultOAuth2AccessToken;
    }
}
